import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
import vuexPersist from "vuex-persist";

export default new Vuex.Store({
  state: {
    tjd:
    [

        {name:'西游记',stat:0},
        {name:'钢铁侠',stat:1},
        {name:'lol',stat:2},
        {name:'极限挑战',stat:3},
        {name:'足球',stat:4},

    ],
  },
  mutations: {
    remove(state,i){
      state.tjd.splice(i,1)
    },
    add(state,obj){
      console.log({name:obj.tj,stat:obj.flag});
      if(obj.tj==''){
        alert('输入不能为空')
      }

      let arr=state.tjd.filter((item)=>{
        return item.name==obj.tj
      })
      if(arr.length>0){
        alert('输入重复')
      }else{
              state.tjd.push({name:obj.tj,stat:obj.flag})
      }

      this.tj=''
    }
  },
  
  actions: {},
  modules: {},
  plugins: [
    new vuexPersist({
      storage: window.localStorage,
    }).plugin,
  ],
  //插件 配置持久化插件
});
